package core

class DocumentTypeController {
	
	static layout = 'country'
	
	def createDoc()
	{
			
	}
	def update() {
		def documentType =  DocumentType.get(params.long('id'))
		documentType.properties = params
		if(documentType.save()) {
			flash.notice = "Document type: ${documentType.name} was updated"
			redirect action:'index'
		}
		else {
			flash.error = "Document type:  failed to be update"
			render(view:'editDoc',model:[documentType: documentType])
		}
	}
	
	def editDoc()
	{
		[documentType: DocumentType.get(params.long('id'))]	
	}
	
	def deleteDoc()
	{
	def document =  DocumentType.get(params.id)
	   
		document.delete()
		redirect(action:'index')	
	}
	
	def save() {
		def document = new DocumentType(params)
		
		if (document.save()) {
			flash.notice = "DocumentType ${document.name}: is saved successfuly"
			redirect(action:'index')
		} else {
			flash.error = "DocumentType ${document.name}: Failed to save"
			render view:'createDoc', model:[document:document]
		}
	}

    def index() { 
		
		def max = params.long('max')?:10
		def start = params.long('start')?:0
		[documents:DocumentType.list(max: max, offset:start ),max:max, start:start ]
		
		
	}
	
//	def documents() {
//		def map = [ documents: DocumentType.list() ]
//		render(view: "show", model: map)
//	}
	
	def show() {
		
				[documentType: DocumentType.get(params.long('id'))]
			}
}
